def calculate_end_time(start_hour, start_minute, duration_minutes):
    # 计算总分钟数
    total_minutes = start_hour * 60 + start_minute + duration_minutes
    
    # 计算结束时刻的小时和分钟
    end_hour = total_minutes // 60
    end_minute = total_minutes % 60
    
    # 如果结束时刻的小时超过24，则减去24以保持在一天之内
    if end_hour >= 24:
        end_hour -= 24
    
    return end_hour, end_minute

# 示例输入
start_hour = int(input())
start_minute = int(input())
duration_minutes = int(input())

# 计算并输出结束时刻
end_hour, end_minute = calculate_end_time(start_hour, start_minute, duration_minutes)
print(end_hour)
print(end_minute)